<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="activity">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>New Activity!</title>
	<link type="text/css" rel="stylesheet" href="css/style.css" />
	<link type="text/css" rel="stylesheet" href="http://alpha.hojoki.com/static/fonts/pictos-font/pictos.css" />
	<script type="text/javascript" src="js/jquery/jquery-1.6.min.js" charset="utf-8"></script>
	<script type="text/javascript" src="js/AIRAliases.js" charset="utf-8"></script>
	<script type="text/javascript" src="js/Timer.js" charset="utf-8"></script>
	
	<script type="text/javascript" charset="utf-8">
		// Closes the window
		var closeWindow = function (){
			window.nativeWindow.stage.removeEventListener('mouseOver',mouseOver);	
			window.nativeWindow.stage.removeEventListener('mouseOut',mouseOut);
			jQuery('body').fadeOut(1000, function() {
				window.nativeWindow.close();
				timer = null;
			});
		};
		
		// Sets the window display properties
		var timer;
		var hasTags = false;
		var hasFile = false;
		onLoad = function (){
			jQuery('.activity').html(window.activityHTML);
			
			// check what kind of activity notification it is
			if(window.activityHTML.search(/class="widget-tag"/) > -1) hasTags = true;
			if(window.activityHTML.search(/class="widget-file"/) > -1) hasFile = true;			
			
			// Initiates the windows dimensions and coordinates, fades the window in and adds listeners to mouse effects
			resize();			
			jQuery('body').fadeTo(500,0.75);
			
			window.nativeWindow.stage.addEventListener('mouseOver',mouseOver);	
			window.nativeWindow.stage.addEventListener('mouseOut',mouseOut);
			

			// let 4 seconds pass until the window initiates closing
			timer = new Timer(function() {
			    closeWindow();
			}, 5000);

		};
		
		var mouseOver = function() {
			window.nativeWindow.stage.removeEventListener('mouseOut',mouseOut);
		    jQuery('body').css("opacity","0.9");
			jQuery('#activity .activity .content').css('white-space','normal');
			if(hasTags) jQuery('#activity .activity .widget-tag-list').show();
			if(hasFile) jQuery('#activity .activity .widget-file-list').show();
			resize();
			timer.pause();
			setTimeout(function() {
				window.nativeWindow.stage.addEventListener('mouseOut',mouseOut);
			}, 100 );	
		}
		
		var mouseOut = function() {
			window.nativeWindow.stage.removeEventListener('mouseOver',mouseOver);	
		    jQuery('body').css("opacity","0.75");
			jQuery('#activity .activity .content').css('white-space','nowrap');
			if(hasTags) jQuery('#activity .activity .widget-tag-list').hide();
			if(hasFile) jQuery('#activity .activity .widget-file-list').hide();
			resize();
			timer.resume();
			setTimeout(function() {
				window.nativeWindow.stage.addEventListener('mouseOver',mouseOver);
			}, 100 );	
		}
		
		// Sets the window width, height, x and y everytime it is being resized
		var initialFixH = 10;
		var resize = function() {
			window.nativeWindow.width = jQuery('body').width()+10;
			window.nativeWindow.height = jQuery('body').height()+10;
			window.nativeWindow.x = air.Screen.screens[0].bounds.width - window.nativeWindow.width - 20;
			window.nativeWindow.y = air.Screen.screens[0].bounds.height - window.nativeWindow.height - 60 + initialFixH;
			initialFixH = 0;
		};

		
		// Open link in user's default browser window.
		function openExternalURL(href) {
			var request = new air.URLRequest(href);
			air.navigateToURL(request);
		}

		// External Links
		jQuery('a[href^=http]').live("click", function(event){
			event.preventDefault();
			openExternalURL(this.href);
		})
		
		// provide a link to hojoki when clicking on the userpic
		jQuery('#activity .activity .widget-person').live("click", function(event){
			event.preventDefault();
			openExternalURL('http://alpha.hojoki.com');
		})
		
	</script>
	
</head>
<body onload="onLoad();">
	<div class="activity"></div>
	<button name="close" type="button" onClick="closeWindow()"></button>
</body>
</html>

